package com.example.cmtwo.controller;

import com.example.cmtwo.bean.Commodity;
import com.example.cmtwo.service.getCommoditybylhservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

/**
 * @作者 CenturyLi
 * @时间 2020-06-03 15:33
 * @功能
 */
@Controller
public class Mapcontroller {
    @Autowired
    getCommoditybylhservice getCommoditybylhservice;

    Commodity commodity;

    @ResponseBody
    @RequestMapping(value = "/map/lh",method = RequestMethod.GET)
    public Map<Integer, Map> map(@RequestParam("lh") Integer lh)
    {

        List<Commodity> com = new LinkedList<Commodity>();
        Map<Integer, Map> list = new HashMap<Integer, Map>();

        com = getCommoditybylhservice.getCommodityByLH(lh);
        System.out.println("1111111111");
        Integer item = 0;

        for(Iterator i = com.iterator(); i.hasNext(); ){
            Map<String, String> map = new HashMap<String, String>();
            commodity = (Commodity) i.next();
            map.put("Cid", commodity.getCid().toString());
            String Cname = commodity.getCname();
            if (commodity.getCname().length() > 14)
            {
                Cname = commodity.getCname().substring(0,14);
                Cname+="...";
            }
            map.put("Cname", Cname);
            map.put("Price", commodity.getPrice().toString());
            map.put("Image", commodity.getImage());
            map.put("lh", commodity.getLh().toString());
            list.put(item, map);
            item++;
        }
        return list;
    }
}
